log using "C:\Users\A\Google Drive (aco.investimentos@gmail.com)\2 - Textos\2020-08\Artigo Final.smcl", replace
use "C:\Users\A\Google Drive (aco.investimentos@gmail.com)\2 - Textos\2020-08\Artigo Final.dta", clear
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
**** Inclur uma vari�vel para as tarifas do Brasil
**** Modelo Gravitacional Tradicinal - Estima��o 3
**** Estima��o com PPML 
**** Modelo tradicional com tarifas e com efeitos fixos para os termos de resist�ncia multilateral
**** Modelo com tarifas de exporta��es e importa��es para o Brasil 
ppml_panel_sg TRADE LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta ln_DIST contig colony comlang_off, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) pred(fitall_3) nopair genS(o_FE_3) genM(d_FE_3) genO(OMR_3) genI(IMR_3)
* Store the results
estimates store e3
*** Fitted Value 
gen fit = ln(fitall_3)
*** (Fitted Value)^2
generate fit2 =fit^2
***Residuals
gen ehat1=TRADE-fitall_3
***(Residuals)^2
gen ehat2=ehat1^2
*Perform heteroskedasticity test
*Graphic
twoway (scatter ehat1 fit), title("e3", size(vsmall)) ytitle(Residuals) xtitle(Fitted values)  xlabel(, nolabels) yline(0)
graph copy G3
*Park/MaMu test
glm ehat2 fit, family(poisson) diff iter(30)
* Store the results
estimates store P3
test fit=0
test fit=1
test fit=2
* Reset Test
ppml_panel_sg TRADE fit2 LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta ln_DIST contig colony comlang_off, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) pred(fitall) nopair max(50000) multi
* Store the results
estimates store R3
test fit2 = 0
drop fit* ehat*
******************************************************************************************************************************
******************************************************************************************************************************
*** Fun��o de Produ��o
* creating the variable product  */
gen output = rgdpna_o
label variable output "output for source countries"
*  creating the variable expenditures  */
bysort year  ReporterISO3_d : egen expndr = sum (TRADE)
label variable expndr "expenditures for destination countries"
qui tab ( PartnerISO3_o ), gen (c_)
qui tab (year), gen (y_)
gen empeffective = emp_o*hc_o
label variable empeffective "employment in effective units"
gen ll = log(empeffective)
label variable ll "ln(empeffective)"
gen lk = log(rkna_o)
label variable lk "ln(capital)"
gen lomr_bsln = log(1/  OMR_3  )
label variable lomr_bsln "ln(1/omr_bsln)"
gen lrgdpna_ido = log(rgdpna_o)
label variable lrgdpna_ido "ln(rgdpna_ido)"
*estimating the Cobb-Douglas unrestricted 
reg lrgdpna_ido ll lk y_* c_*, vce(boot)
* Store the results
estimates store CD1_3
* estimating the Cobb-Douglas restricted  
constraint 1 ll + lk = 1
 
cnsreg lrgdpna_ido ll lk y_* c_*, constraint (1) vce(boot)
* Store the results
estimates store CD2_3
* estimating the unrestricted structural model equation of Anderson, Larch and Yotov  */
reg lrgdpna_ido ll lk lomr_bsln y_* c_*, vce(boot)
* Store the results
estimates store CD3_3
gen sigma1_3 = (1/(_b[lomr_bsln] ))
gen a1_3 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk1_3 =(_b[ll] )+(_b[lk] )
gen k1_3 = (1+(_b[lomr_bsln ] ))
*estimating the restricted structural model of Anderson, Larch and Yotov
constraint 2 ll + lk = 1 + lomr_bsln
cnsreg lrgdpna_ido ll lk lomr_bsln y_* c_*, constraint (2) vce(boot)
* Store the results
estimates store CD4_3
predict lrgdpna_idop if e(sample)  
corr lrgdpna_ido lrgdpna_idop if e(sample)
di r(rho)^2
gen sigma2_3 = (1/(_b[lomr_bsln] ))
gen a2_3 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk2_3 =(_b[ll] )+(_b[lk] )
gen k2_3 = (1+(_b[lomr_bsln ] ))
drop output expndr c_*  y_* empeffective ll lk lomr_bsln lrgdpna_ido 
*** Fun��o de acumula��o de capital
qui tab (ReporterISO3_d ), gen (d_)
qui tab (year), gen (y_)
gen lk_idd = log(rkna_d)
label variable lk_idd "log(rkna_idd)"
gen lrgdpna_idd = log(rgdpna_d)
label variable lrgdpna_idd "log(rgdpna_idd)"
gen limr_bsln = log( IMR_3 )
label variable limr_bsln "ln(imr_bsln)"
xtset pair_id year
sort pair_id year
sort year pair_id
xtset pair_id year
sort pair_id year
gen lk_idd_1 = L1.lk_idd
label variable lk_idd_1 "lag for lrkna_idd"
gen lrgdpna_idd_1 = L1.lrgdpna_idd
label variable lrgdpna_idd_1 "lag for lrgdpna_idd"
gen limr_bsln_1 = L1.limr_bsln
label variable limr_bsln_1 "lag for limr_bsln"
* estimating the unrestricted structural model of Anderson, Larch and Yotov  */
constraint 3  limr_bsln_1 = - lrgdpna_idd_1
constraint 4 lk_idd_1 = 1 - lrgdpna_idd_1
reg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, vce(boot)
* Store the results
estimates store KA1_3
* estimating the restricted structural model of Anderson, Larch and Yotov  */
cnsreg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, constraint (3 4) vce(boot)
* Store the results
estimates store KA2_3
predict lk_iddp if e(sample)  
corr lk_idd lk_iddp if e(sample)
di r(rho)^2
drop d_* y_* lk_* lrgdpna* limr_bsln*
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
**** Modelo Gravitacional Tradicinal - Estima��o 4
**** Estima��o com PPML 
**** Modelo tradicional com tarifas e com efeitos fixos para os termos de resist�ncia multilateral
**** Modelo com efeitos fixos para os pares de pa�ses para corrigirem problemas de heterogeneidade
**** Modelo com tarifas de exporta��es e importa��es para o Brasil 
ppml_panel_sg TRADE LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) pred(fitall_4) genS(o_FE_4) genM(d_FE_4) genO(OMR_4) genI(IMR_4) genD(Dij_FE_4)
* Store the results
estimates store e4
*** Fitted Value 
gen fit = ln(fitall_4)
*** (Fitted Value)^2
generate fit2 =fit^2
***Residuals
gen ehat1=TRADE-fitall_4
***(Residuals)^2
gen ehat2=ehat1^2
*Perform heteroskedasticity test
*Graphic
twoway (scatter ehat1 fit), title("e4", size(vsmall)) ytitle(Residuals) xtitle(Fitted values)  xlabel(, nolabels) yline(0)
graph copy G4
*Park/MaMu test
glm ehat2 fit, family(poisson) diff iter(30)
* Store the results
estimates store P4
test fit=0
test fit=1
test fit=2
* Reset Test
ppml_panel_sg TRADE fit2 LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) max(50000) multi
* Store the results
estimates store R4
test fit2 = 0
drop fit* ehat*
******************************************************************************************************************************
******************************************************************************************************************************
*** Fun��o de Produ��o
* creating the variable product  */
gen output = rgdpna_o
label variable output "output for source countries"
*  creating the variable expenditures  */
bysort year  ReporterISO3_d : egen expndr = sum (TRADE)
label variable expndr "expenditures for destination countries"
qui tab ( PartnerISO3_o ), gen (c_)
qui tab (year), gen (y_)
gen empeffective = emp_o*hc_o
label variable empeffective "employment in effective units"
gen ll = log(empeffective)
label variable ll "ln(empeffective)"
gen lk = log(rkna_o)
label variable lk "ln(capital)"
gen lomr_bsln = log(1/  OMR_4  )
label variable lomr_bsln "ln(1/omr_bsln)"
gen lrgdpna_ido = log(rgdpna_o)
label variable lrgdpna_ido "ln(rgdpna_ido)"
*estimating the Cobb-Douglas unrestricted 
reg lrgdpna_ido ll lk y_* c_*, vce(boot)
* Store the results
estimates store CD1_4
* estimating the Cobb-Douglas restricted  
constraint 1 ll + lk = 1
 
cnsreg lrgdpna_ido ll lk y_* c_*, constraint (1) vce(boot)
* Store the results
estimates store CD2_4
* estimating the unrestricted structural model equation of Anderson, Larch and Yotov  */
reg lrgdpna_ido ll lk lomr_bsln y_* c_*, vce(boot)
* Store the results
estimates store CD3_4
gen sigma1_4 = (1/(_b[lomr_bsln] ))
gen a1_4 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk1_4 =(_b[ll] )+(_b[lk] )
gen k1_4 = (1+(_b[lomr_bsln ] ))
*estimating the restricted structural model of Anderson, Larch and Yotov
constraint 2 ll + lk = 1 + lomr_bsln
cnsreg lrgdpna_ido ll lk lomr_bsln y_* c_*, constraint (2) vce(boot)
* Store the results
estimates store CD4_4
predict lrgdpna_idop if e(sample)  
corr lrgdpna_ido lrgdpna_idop if e(sample)
di r(rho)^2
gen sigma2_4 = (1/(_b[lomr_bsln] ))
gen a2_4 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk2_4 =(_b[ll] )+(_b[lk] )
gen k2_4 = (1+(_b[lomr_bsln ] ))
drop output expndr c_*  y_* empeffective ll lk lomr_bsln lrgdpna_ido 
*** Fun��o de acumula��o de capital
qui tab (ReporterISO3_d ), gen (d_)
qui tab (year), gen (y_)
gen lk_idd = log(rkna_d)
label variable lk_idd "log(rkna_idd)"
gen lrgdpna_idd = log(rgdpna_d)
label variable lrgdpna_idd "log(rgdpna_idd)"
gen limr_bsln = log( IMR_4 )
label variable limr_bsln "ln(imr_bsln)"
xtset pair_id year
sort pair_id year
sort year pair_id
xtset pair_id year
sort pair_id year
gen lk_idd_1 = L1.lk_idd
label variable lk_idd_1 "lag for lrkna_idd"
gen lrgdpna_idd_1 = L1.lrgdpna_idd
label variable lrgdpna_idd_1 "lag for lrgdpna_idd"
gen limr_bsln_1 = L1.limr_bsln
label variable limr_bsln_1 "lag for limr_bsln"
* estimating the unrestricted structural model of Anderson, Larch and Yotov  */
constraint 3  limr_bsln_1 = - lrgdpna_idd_1
constraint 4 lk_idd_1 = 1 - lrgdpna_idd_1
reg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, vce(boot)
* Store the results
estimates store KA1_4
* estimating the restricted structural model of Anderson, Larch and Yotov  */
cnsreg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, constraint (3 4) vce(boot)
* Store the results
estimates store KA2_4
predict lk_iddp if e(sample)  
corr lk_idd lk_iddp if e(sample)
di r(rho)^2
drop d_* y_* lk_* lrgdpna* limr_bsln*
xtset pair_id year, yearly
*** Proxima etapa � realizar as estima��es
sort ReporterISO3_d PartnerISO3_o year
*** A base utilizada na pesquisa n�o considera os fluxos comerciais intranacionais
drop if PartnerISO3_o == ReporterISO3_d
*** Anderson, Larch e Yotov (2014) e Yotov et. al. (2016) sugerem que as estima��es considerem intervalos temporais regulares e espa�ados para captarem as varia��es nos TRM
keep if year == 2008 | year ==2012 | year == 2016
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
**** Inclur uma vari�vel para as tarifas do Brasil
**** Modelo Gravitacional Tradicinal - Estima��o 7
**** Estima��o com PPML 
**** Modelo tradicional com tarifas e com efeitos fixos para os termos de resist�ncia multilateral
**** Modelo com tarifas de exporta��es e importa��es para o Brasil 
ppml_panel_sg TRADE LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta ln_DIST contig colony comlang_off, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) pred(fitall_7) nopair genS(o_FE_7) genM(d_FE_7) genO(OMR_7) genI(IMR_7)
* Store the results
estimates store e7
*** Fitted Value 
gen fit = ln(fitall_7)
*** (Fitted Value)^2
generate fit2 =fit^2
***Residuals
gen ehat1=TRADE-fitall_7
***(Residuals)^2
gen ehat2=ehat1^2
*Perform heteroskedasticity test
*Graphic
twoway (scatter ehat1 fit), title("e7", size(vsmall)) ytitle(Residuals) xtitle(Fitted values)  xlabel(, nolabels) yline(0)
graph copy G7
*Park/MaMu test
glm ehat2 fit, family(poisson) diff iter(30)
* Store the results
estimates store P7
test fit=0
test fit=1
test fit=2
* Reset Test
ppml_panel_sg TRADE fit2 LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta ln_DIST contig colony comlang_off, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) pred(fitall) nopair max(50000) multi
* Store the results
estimates store R7
test fit2 = 0
drop fit* ehat*
******************************************************************************************************************************
******************************************************************************************************************************
*** Fun��o de Produ��o
* creating the variable product
gen output = rgdpna_o
label variable output "output for source countries"
*  creating the variable expenditures  */
bysort year  ReporterISO3_d : egen expndr = sum (TRADE)
label variable expndr "expenditures for destination countries"
qui tab ( PartnerISO3_o ), gen (c_)
qui tab (year), gen (y_)
gen empeffective = emp_o*hc_o
label variable empeffective "employment in effective units"
gen ll = log(empeffective)
label variable ll "ln(empeffective)"
gen lk = log(rkna_o)
label variable lk "ln(capital)"
gen lomr_bsln = log(1/  OMR_7  )
label variable lomr_bsln "ln(1/omr_bsln)"
gen lrgdpna_ido = log(rgdpna_o)
label variable lrgdpna_ido "ln(rgdpna_ido)"
*estimating the Cobb-Douglas unrestricted 
reg lrgdpna_ido ll lk y_* c_*, vce(boot)
* Store the results
estimates store CD1_7
* estimating the Cobb-Douglas restricted  
constraint 1 ll + lk = 1
 
cnsreg lrgdpna_ido ll lk y_* c_*, constraint (1) vce(boot)
* Store the results
estimates store CD2_7
* estimating the unrestricted structural model equation of Anderson, Larch and Yotov  */
reg lrgdpna_ido ll lk lomr_bsln y_* c_*, vce(boot)
* Store the results
estimates store CD3_7
gen sigma1_7 = (1/(_b[lomr_bsln] ))
gen a1_7 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk1_7 =(_b[ll] )+(_b[lk] )
gen k1_7 = (1+(_b[lomr_bsln ] ))
*estimating the restricted structural model of Anderson, Larch and Yotov
constraint 2 ll + lk = 1 + lomr_bsln
cnsreg lrgdpna_ido ll lk lomr_bsln y_* c_*, constraint (2) vce(boot)
* Store the results
estimates store CD4_7
predict lrgdpna_idop if e(sample)  
corr lrgdpna_ido lrgdpna_idop if e(sample)
di r(rho)^2
gen sigma2_7 = (1/(_b[lomr_bsln] ))
gen a2_7 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk2_7 =(_b[ll] )+(_b[lk] )
gen k2_7 = (1+(_b[lomr_bsln ] ))
drop output expndr c_*  y_* empeffective ll lk lomr_bsln lrgdpna_ido 
*** Fun��o de acumula��o de capital
qui tab (ReporterISO3_d ), gen (d_)
qui tab (year), gen (y_)
gen lk_idd = log(rkna_d)
label variable lk_idd "log(rkna_idd)"
gen lrgdpna_idd = log(rgdpna_d)
label variable lrgdpna_idd "log(rgdpna_idd)"
gen limr_bsln = log( IMR_7 )
label variable limr_bsln "ln(imr_bsln)"
xtset pair_id year
sort pair_id year
sort year pair_id
xtset pair_id year
sort pair_id year
gen lk_idd_1 = L4.lk_idd
label variable lk_idd_1 "lag for lrkna_idd"
gen lrgdpna_idd_1 = L4.lrgdpna_idd
label variable lrgdpna_idd_1 "lag for lrgdpna_idd"
gen limr_bsln_1 = L4.limr_bsln
label variable limr_bsln_1 "lag for limr_bsln"
* estimating the unrestricted structural model of Anderson, Larch and Yotov  */
reg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, vce(boot)
* Store the results
estimates store KA1_7
* estimating the restricted structural model of Anderson, Larch and Yotov  */
constraint 3  limr_bsln_1 = - lrgdpna_idd_1
constraint 4 lk_idd_1 = 1 - lrgdpna_idd_1
cnsreg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, constraint (3 4) vce(boot)
* Store the results
estimates store KA2_7
predict lk_iddp if e(sample)  
corr lk_idd lk_iddp if e(sample)
di r(rho)^2
drop d_* y_* lk_* lrgdpna* limr_bsln* 
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
******************************************************************************************************************************
**** Modelo Gravitacional Tradicinal - Estima��o 8
**** Estima��o com PPML 
**** Modelo tradicional com tarifas e com efeitos fixos para os termos de resist�ncia multilateral
**** Modelo com efeitos fixos para os pares de pa�ses para corrigirem problemas de heterogeneidade
**** Modelo com tarifas de exporta��es e importa��es para o Brasil 
ppml_panel_sg TRADE LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) pred(fitall_8) genS(o_FE_8) genM(d_FE_8) genO(OMR_8) genI(IMR_8) genD(Dij_FE_8)  
* Store the results
estimates store e8
*** Fitted Value 
gen fit = ln(fitall_8)
*** (Fitted Value)^2
generate fit2 =fit^2
***Residuals
gen ehat1=TRADE-fitall_8
***(Residuals)^2
gen ehat2=ehat1^2
*Perform heteroskedasticity test
*Graphic
twoway (scatter ehat1 fit), title("e8", size(vsmall)) ytitle(Residuals) xtitle(Fitted values)  xlabel(, nolabels) yline(0)
graph copy G8
*Park/MaMu test
glm ehat2 fit, family(poisson) diff iter(30)
* Store the results
estimates store P8
test fit=0
test fit=1
test fit=2
* Reset Test
ppml_panel_sg TRADE fit2 LN_WA_TARIFA_FINAL BRA_imp_LN_WA_TAF_F BRA_exp_LN_WA_TAF_F rta, ex( PartnerISO3_o ) im( ReporterISO3_d ) y(year) max(50000) multi
* Store the results
estimates store R8
test fit2 = 0
drop fit* ehat*
******************************************************************************************************************************
******************************************************************************************************************************
*** Fun��o de Produ��o
* creating the variable product
gen output = rgdpna_o
label variable output "output for source countries"
*  creating the variable expenditures  */
bysort year  ReporterISO3_d : egen expndr = sum (TRADE)
label variable expndr "expenditures for destination countries"
qui tab ( PartnerISO3_o ), gen (c_)
qui tab (year), gen (y_)
gen empeffective = emp_o*hc_o
label variable empeffective "employment in effective units"
gen ll = log(empeffective)
label variable ll "ln(empeffective)"
gen lk = log(rkna_o)
label variable lk "ln(capital)"
gen lomr_bsln = log(1/  OMR_8  )
label variable lomr_bsln "ln(1/omr_bsln)"
gen lrgdpna_ido = log(rgdpna_o)
label variable lrgdpna_ido "ln(rgdpna_ido)"
*estimating the Cobb-Douglas unrestricted 
reg lrgdpna_ido ll lk y_* c_*, vce(boot)
* Store the results
estimates store CD1_8
* estimating the Cobb-Douglas restricted  
constraint 1 ll + lk = 1
 
cnsreg lrgdpna_ido ll lk y_* c_*, constraint (1) vce(boot)
* Store the results
estimates store CD2_8
* estimating the unrestricted structural model equation of Anderson, Larch and Yotov  */  lrgdpna_ido ll lk lomr_bsln
reg lrgdpna_ido ll lk lomr_bsln y_* c_*, vce(boot)
* Store the results
estimates store CD3_8
gen sigma1_8 = (1/(_b[lomr_bsln] ))
gen a1_8 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk1_8 =(_b[ll] )+(_b[lk] )
gen k1_8 = (1+(_b[lomr_bsln ] ))
*estimating the restricted structural model of Anderson, Larch and Yotov
constraint 2 ll + lk = 1 + lomr_bsln
cnsreg lrgdpna_ido ll lk lomr_bsln y_* c_*, constraint (2) vce(boot)
* Store the results
estimates store CD4_8
predict lrgdpna_idop if e(sample)  
corr lrgdpna_ido lrgdpna_idop if e(sample)
di r(rho)^2
gen sigma2_8 = (1/(_b[lomr_bsln] ))
gen a2_8 = ((_b[lk] )/(1+(_b[lomr_bsln ] )))
gen kk2_8 =(_b[ll] )+(_b[lk] )
gen k2_8 = (1+(_b[lomr_bsln ] ))
drop output expndr c_*  y_* empeffective ll lk lomr_bsln lrgdpna_ido 
*** Fun��o de acumula��o de capital
qui tab (ReporterISO3_d ), gen (d_)
qui tab (year), gen (y_)
gen lk_idd = log(rkna_d)
label variable lk_idd "log(rkna_idd)"
gen lrgdpna_idd = log(rgdpna_d)
label variable lrgdpna_idd "log(rgdpna_idd)"
gen limr_bsln = log( IMR_8 )
label variable limr_bsln "ln(imr_bsln)"
xtset pair_id year
sort pair_id year
sort year pair_id
xtset pair_id year
sort pair_id year
gen lk_idd_1 = L4.lk_idd
label variable lk_idd_1 "lag for lrkna_idd"
gen lrgdpna_idd_1 = L4.lrgdpna_idd
label variable lrgdpna_idd_1 "lag for lrgdpna_idd"
gen limr_bsln_1 = L4.limr_bsln
label variable limr_bsln_1 "lag for limr_bsln"
* estimating the unrestricted structural model of Anderson, Larch and Yotov  */
reg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, vce(boot)
* Store the results
estimates store KA1_8
* estimating the restricted structural model of Anderson, Larch and Yotov  */
constraint 3  limr_bsln_1 = - lrgdpna_idd_1
constraint 4 lk_idd_1 = 1 - lrgdpna_idd_1
cnsreg lk_idd lrgdpna_idd_1 lk_idd_1 limr_bsln_1 y_* d_*, constraint (3 4) vce(boot)
* Store the results
estimates store KA2_8
predict lk_iddp if e(sample)  
corr lk_idd lk_iddp if e(sample)
di r(rho)^2
drop d_* y_* lk_* lrgdpna* limr_bsln*
